package app

import (
	// "fmt"
	// "time"
	// "encoding/json"
	// "io/ioutil"

	"github.com/go-apibox/api"
	"github.com/go-apibox/filter"
)

// 获取分组列表
func ActionMockGroupList(c *api.Context) interface{} {
	return nil
}

// 获取任务
// 总体任务状态

type MockTask struct {
	Name        string
	TotalCount  int // 总数
	DoneCount   int // 完成
	FailedCount int // 失败
	Retry       int ///
	StartTime   int
	DoneTime    int
}

type MockProduct struct {
	ProductId    uint32
	Addr         string
	Account      string // 逛号
	ProductCode  string
	ProductTitle string
	ReleaseTime  string
	IsStart      string
	HoldSec      int
}

type MockRespProductGet struct {
	TaskInfo *MockTask    // 任务信息
	Product  *MockProduct // 任务

}

// type MockDoneTaskInfo struct {
// 	ProductId uint32 // 必选
// 	ImgBase64 string // 可选
// 	ImgUrl    string // 可选
// }

// type MockReqProductGet struct {
// 	DeviceId  uint32
// 	DoneTasks []*MockDoneTaskInfo
// }

func ActionMock2ProductNext(c *api.Context) interface{} {
	params := c.NewParams()
	params.Add("DeviceId", filter.EmptyToNil(), filter.Required(), filter.Uint32())
	params.Add("ProductId", filter.EmptyToNil(), filter.Uint32())
	params.Add("ImgBase64", filter.EmptyToNil(), filter.String())
	params.Add("ImgUrl", filter.EmptyToNil(), filter.String())
	if apiErr := params.Parse(); apiErr != nil {
		return apiErr
	}

	dId := params.GetUint32("DeviceId")
	pId := params.GetUint32("ProductId")
	app.logger.Debug(dId)
	app.logger.Debug(pId)

	// if time.Now().Second()%2 == 0 {
	// 	time.Sleep(time.Second * 10)
	// 	resp := &MockRespProductGet{
	// 		TaskInfo: &MockTask{
	// 			Name:        "mock task",
	// 			TotalCount:  0,
	// 			DoneCount:   0,
	// 			FailedCount: 0,
	// 			Retry:       3,
	// 			StartTime:   123,
	// 			DoneTime:    0,
	// 		},
	// 	}

	// 	return resp
	// }

	resp := &MockRespProductGet{
		TaskInfo: &MockTask{
			Name:        "mock task",
			TotalCount:  100,
			DoneCount:   12,
			FailedCount: 1,
			Retry:       3,
			StartTime:   123,
			DoneTime:    0,
		},
		Product: &MockProduct{
			ProductId:    234,
			Addr:         "https://market.m.taobao.com/app/tb-source-app/video-fullpage/pages/index2?wh_weex=false&wx_navbar_hidden=true&wx_navbar_transparent=true&type=guangguang&source=guangguang&id=419443840476",
			Account:      "番茄炒蛋蛋蛋黄派1",
			ProductCode:  "420150986584",
			ProductTitle: "虾仁黑木耳炒百合怎么炒好吃",
			ReleaseTime:  "14",
			IsStart:      "",
			HoldSec:      5,
		},
	}

	return resp

}
